import { customRef } from "vue";
export function debouncedRef<T>(
    value: T
) {
    let timeoutId: ReturnType<typeof setTimeout>;
    return customRef<T>((track, trigger) => {
        return {
            get() {
                track();
                return value;
            },
            set(newValue: T) {
                clearTimeout(timeoutId);
                timeoutId = setTimeout(() => {
                    value = newValue;
                    trigger();
                }, 1000);
            }
        };
    });
}